﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using JSC.Portal.Web;
using JSC.Portal.Services;
using JSC.Core;
using System.Threading;

namespace JSC.Portal.Web.App
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801
    public class MvcApplication : PortalApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            string defaultCulture = Thread.CurrentThread.CurrentUICulture.Name;
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute("FriendlyUrl", "{language}/site" + SiteSettings.APP_EXTENSION + "/{*friendlyurl}",
               new { controller = "PortalEngine", action = "ShowFriendlyUrl", language = defaultCulture, friendlyurl = "/" });
            routes.MapRoute("Section", "section" + SiteSettings.APP_EXTENSION + "/{sectionid}",
                new { controller = "PortalEngine", action = "ShowSection", sectionid = -1 });
            routes.MapRoute("Portal",
                "portal/{controller}" + SiteSettings.APP_EXTENSION + "/{action}/{id}/{sectionid}", new { controller = "PortalSites", action = "List", id = -1, sectionid = (int?)null });
            routes.MapRoute("RootLanguage", "{language}",
                new { controller = "PortalEngine", action = "ShowFriendlyUrl", language = "", friendlyurl = "/" });
        }

        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.Configure();

            RegisterRoutes(RouteTable.Routes);

            ViewEngines.Engines.Add(new PortalViewEngine());
        }
    }

    public class SiteSettings
    {
        public static string APP_EXTENSION = ".aspx";
    }
}